package com.woniuxy.mapper;

import com.woniuxy.entity.Chat;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChatMapper {
    @Select("""
        SELECT * FROM chat
        WHERE (publisher_id = #{param1} AND consumer_id = #{param2}) 
           OR (publisher_id = #{param2} AND consumer_id = #{param1}) 
        ORDER BY time
        """)
    List<Chat> getChat(Integer publisherId, Integer consumerId);

    @Insert("INSERT INTO chat (content,publisher_id,time,consumer_id,readed) " +
            "values ( #{content} , #{publisherId} , #{time} , #{consumerId}  , #{readed} )")
    void add(Chat imSingle);
}
